#include <iostream>
#include <string>
#include <memory>

class computer
{
public:
    computer(){};

    void setBoard(const std::string& board)
    {
        _board = board;
    }

    void setDisplay(const std::string& display)
    {
        _display = display;
    }

    virtual void setOs() = 0;

    void showParamaters()
    {
        std::string param = "Computer Param:\n";
        param += "\tBoard: " + _board + "\n";
        param += "\tDisplay: " + _display + "\n";
        param += "\tOs: " + _os + "\n";

        std::cout << param << std::endl;

    }

    ~computer(){};

protected:
    std::string _board;
    std::string _display;
    std::string _os;
};

class MacBook : public computer
{
public:
    void setOs() override
    {
        _os = "Mac OS x12";
    }
};

class Builder
{
public:
    virtual void BuilderBoard(const std::string& board) = 0;
    virtual void BuilderDisplay(const std::string& display) = 0;
    virtual void BuilderOs() = 0;
    virtual std::shared_ptr<computer> Build() = 0;
};


class MacBookBuilder : public Builder
{
public:
    MacBookBuilder()
    :_computer(new MacBook()){}

    void BuilderBoard(const std::string& board)
    {
        _computer->setBoard(board);
    }

    void BuilderDisplay(const std::string& display)
    {
        _computer->setDisplay(display);
    }

    void BuilderOs()
    {
        _computer->setOs();
    }

    std::shared_ptr<computer> Build()
    {
        return _computer;
    }

private:
    std::shared_ptr<computer> _computer;
};

class Director 
{
public:
    Director(Builder* builder)
    :_builder(builder){};

    void construct(const std::string& board, const std::string& display)
    {
        _builder->BuilderBoard(board);
        _builder->BuilderDisplay(display);
        _builder->BuilderOs();
    }


private:
    std::shared_ptr<Builder> _builder;
};

int main()
{
    Builder* builder = new MacBookBuilder();
    std::unique_ptr<Director> director(new Director(builder));
    director->construct("华硕主板", "卓伟显示器");
    std::shared_ptr<computer> computer = builder->Build();
    computer->showParamaters();
    return 0;
}